package com.sxu.shadowdrawabledemo;

import com.sxu.shadowdrawabledemo.slice.GridExampleSlice;
import com.sxu.shadowdrawabledemo.slice.ListExampleSlice;
import com.sxu.shadowdrawabledemo.slice.PagerExampleSlice;
import com.sxu.shadowdrawabledemo.slice.RecycleExampleSlice;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.ability.fraction.FractionAbility;
import ohos.aafwk.ability.fraction.FractionManager;
import ohos.aafwk.ability.fraction.FractionScheduler;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.utils.Color;
import ohos.app.Context;

/*******************************************************************************
 * Description:
 *
 * Author: Freeman
 *
 * Date: 2019/2/12
 *
 * Copyright: all rights reserved by Freeman.
 *******************************************************************************/
public class ExampleContainerAbility extends FractionAbility {
    /**
     * list界面的类型
     */
    public static final int CONTAINER_TYPE_LIST = 1;
    /**
     * grid界面的类型
     */
    public static final int CONTAINER_TYPE_GRID = 2;
    /**
     * recycleview界面的类型
     */
    public static final int CONTAINER_TYPE_RECYCLE = 3;
    /**
     * pager界面的类型
     */
    public static final int CONTAINER_TYPE_PAGER = 4;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_example_container_layout);
        getWindow().setStatusBarColor(Color.getIntColor("#303F9F"));
        int containerType = getIntent().getIntParam("containerType", CONTAINER_TYPE_LIST);
        FractionManager fm = getFractionManager();
        FractionScheduler ft = fm.startFractionScheduler();
        Fraction fraction = null;

        if (containerType == CONTAINER_TYPE_LIST) {
            fraction = new ListExampleSlice();
        } else if (containerType == CONTAINER_TYPE_GRID) {
            fraction = new GridExampleSlice();
        } else if (containerType == CONTAINER_TYPE_RECYCLE) {
            fraction = new RecycleExampleSlice();
        } else if (containerType == CONTAINER_TYPE_PAGER) {
            fraction = new PagerExampleSlice();
        } else {
            /**
             * Nothing
             */
        }

        if (fraction != null) {
            ft.add(ResourceTable.Id_container_layout, fraction).submit();
        }
    }
    /**
     * 用于跳转的方法
     *
     * @param context 上下文
     * @param containerType 容器的类型
    */
    public static void enter(Context context, int containerType) {
        Intent intent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withBundleName(context.getBundleName())
                .withAbilityName(ExampleContainerAbility.class.getName())
                .build();
        intent.setParam("containerType", containerType);
        intent.setOperation(operation);
        context.startAbility(intent, 0);
    }
}
